﻿@*
    Copyright (c) Microsoft. All rights reserved.
    Licensed under the MIT license. See LICENSE file in the project root for full license information.
*@

@model Microsoft.Fx.Portability.Reports.RazorHtmlObject

@using Microsoft.Fx.Portability
@using Microsoft.Fx.Portability.ObjectModel
@using Microsoft.Fx.Portability.Reports
@using Microsoft.Fx.Portability.Reports.Html
@using Microsoft.Fx.Portability.Reports.Html.Resources
@using System.Linq

@{
    var reportingResult = Model.ReportingResult;
}

<h2 id="@LocalizedStrings.CompatibilityPageTitle" tabindex="0">@LocalizedStrings.CompatibilityPageTitle</h2>
<div id="summary-compat-byassembly">
    <table>
        <caption class="compat-subheader">@LocalizedStrings.PerAssemblyOverview</caption>
        <tbody>
            <tr>
                <th rowspan="2">@LocalizedStrings.AssemblyHeader</th>
                <th colspan="3" class="textCentered"><abbr title="@LocalizedStrings.RuntimeCompatIssueDescription">@LocalizedStrings.RuntimeIssues</abbr></th>
                <th colspan="3" class="textCentered"><abbr title="@LocalizedStrings.RetargetingCompatIssueDescriptionPlainText">@LocalizedStrings.RetargetingIssues</abbr></th>
            </tr>
            <tr>
                <th><abbr title="@LocalizedStrings.MajorCompatIssueDescription">@LocalizedStrings.Major</abbr></th>
                <th><abbr title="@LocalizedStrings.MinorCompatIssueDescription">@LocalizedStrings.Minor</abbr></th>
                <th><abbr title="@LocalizedStrings.EdgeCompatIssueDescription">@LocalizedStrings.Edge</abbr></th>
                <th><abbr title="@LocalizedStrings.MajorCompatIssueDescription">@LocalizedStrings.Major</abbr></th>
                <th><abbr title="@LocalizedStrings.MinorCompatIssueDescription">@LocalizedStrings.Minor</abbr></th>
                <th><abbr title="@LocalizedStrings.EdgeCompatIssueDescription">@LocalizedStrings.Edge</abbr></th>
            </tr>

            @*Writing the summary body information here.*@
            @foreach (var kvp in Model.OrderedBreakingChangesByAssembly)
            {
                var assembly = kvp.Key;
                if (!Model.OrderedBreakingChangeSkippedAssemblies.Contains(assembly))
                {
                    var breaks = kvp.Value;
                    var majorIssues = breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Major && !b.Key.IsRetargeting);
                    var minorIssues = breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Minor && !b.Key.IsRetargeting);
                    var edgeIssues = breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Edge && !b.Key.IsRetargeting);
                    var majorRetargetingIssues = breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Major && b.Key.IsRetargeting);
                    var minorRetargetingIssues = breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Minor && b.Key.IsRetargeting);
                    var edgeRetargetingIssues = breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Edge && b.Key.IsRetargeting);

                    // Create a link to compat details if they will exist
                    var link = (majorIssues.Count() + minorIssues.Count() + edgeIssues.Count() + majorRetargetingIssues.Count() + minorRetargetingIssues.Count() + edgeRetargetingIssues.Count()) > 0 ?
                                "#Compat-" + assembly :
                                "#" + LocalizedStrings.CompatibilityPageTitle;
                    <tr>
                        <td>
                            <strong>
                                <a href="@link">
                                    <span class="assembly-name">@reportingResult.GetNameForAssemblyInfo(assembly)</span>
                                    @if (!string.IsNullOrEmpty(assembly.TargetFrameworkMoniker))
                                    {
                                        <span class="assembly-tfm">(@assembly.TargetFrameworkMoniker)</span>
                                    }
                                </a>
                            </strong>
                        </td>
                        @Html.BreakingChangeCountCell(majorIssues.Count(), 0, 2)
                        @Html.BreakingChangeCountCell(minorIssues.Count(), 0, 3)
                        @Html.BreakingChangeCountCell(edgeIssues.Count(), 0, 100)
                        @Html.BreakingChangeCountCell(majorRetargetingIssues.Count(), 0, 2)
                        @Html.BreakingChangeCountCell(minorRetargetingIssues.Count(), 0, 3)
                        @Html.BreakingChangeCountCell(edgeRetargetingIssues.Count(), 0, 100)
                    </tr>
                }
            }
        </tbody>
    </table>
    <p>@LocalizedStrings.BreakingChangeDisclaimer</p>
</div>
@if (Model.OrderedBreakingChangeSkippedAssemblies.Count() > 0)
{
    <div id="summary-compat-skippedassemblies">
        <table>
            <caption class="compat-subheader">@LocalizedStrings.IgnoredAssemblies</caption>
            <tr>
                <th>@LocalizedStrings.Assembly</th>
            </tr>
            @foreach (AssemblyInfo assembly in Model.OrderedBreakingChangeSkippedAssemblies)
            {
                <tr>
                    <td>
                        <span class="assembly-name">@assembly</span>
                        @if (!string.IsNullOrEmpty(assembly.TargetFrameworkMoniker))
                        {
                            <span class="assembly-tfm">(@assembly.TargetFrameworkMoniker)</span>
                        }
                    </td>
                </tr>
            }
        </table>
    </div>
}
<div id="summary-compat-bybreakingchange">
    <h3 class="compat-subheader">@LocalizedStrings.SubmissionOverview</h3>

    @Html.Partial("_CompatibilitySummary", new CompatibilitySummaryModel(Model.BreakingChangesSummary, null, null))
</div>
<div id="CompatDetails">
    @{
        foreach (var kvp in Model.OrderedBreakingChangesByAssembly)
        {
            @Html.Partial("_CompatibilitySummary", new CompatibilitySummaryModel(kvp.Value, kvp.Key, reportingResult))
        }
    }
</div>
